package com.shopping_assistant.model;

import java.util.Comparator;

public class Offer {
	
	private String title;

	private int offerId;

	private int offerPrice;
	
	private int normalPrice;
	
	private String duration;
	
	private Shop offerProvider;
	
	private int totalViews;

	public Offer(String title, int offerId, int offerPrice, int normalPrice, String duration, Shop offerProvider, int totalViews) {
		
		this.title = title;
		this.offerId = offerId;
		this.offerPrice = offerPrice;
		this.normalPrice = normalPrice;
		this.duration = duration;
		this.offerProvider = offerProvider;
		
		this.totalViews = totalViews;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public int getOfferId() {
		return offerId;
	}

	public int getOfferPrice() {
		return offerPrice;
	}

	public void setOfferPrice(int offerPrice) {
		this.offerPrice = offerPrice;
	}
	
	public int getNormalPrice() {
		return normalPrice;
	}

	public void setNormalPrice(int normalPrice) {
		this.normalPrice = normalPrice;
	}

	public String getDuration() {
		return duration;
	}

	public void setDuration(String duration) {
		this.duration = duration;
	}

	public Shop getOfferProvider() {
		return offerProvider;
	}

	public void setOfferProvider(Shop offerProvider) {
		this.offerProvider = offerProvider;
	}
	
	public int getTotalViews() {
		return totalViews;
	}
	
	public void countUpTotalViews() {
		totalViews++;
	}
	
	public static Comparator<Offer> compareByViews() {
		return new sortOffers();
	}
	
	private static class sortOffers implements Comparator<Offer> {

		public int compare(Offer lhs, Offer rhs) {
			return rhs.getTotalViews() - lhs.getTotalViews();
		}
	}
	
	@Override
	public String toString() {
		return this.title + " [" + totalViews + "]";
	}
}
